package com.android.library.adapter;

import android.content.Context;
import android.view.ViewGroup;

import androidx.annotation.NonNull;

import java.util.List;

/**
 * @author xiaoxing
 * Created by pengsheng-2 on 2018/8/29.
 */

public abstract class BaseMultiItemAdapter<T> extends BaseAdapter<T> {

    public BaseMultiItemAdapter(Context mContext, List<T> mDatas) {
        super(mContext, -1, mDatas);
    }

    @Override
    public int getItemViewType(int position) {
        return mDatas == null || mDatas.size() == 0 ? 0 :muItemViewType(position,mDatas.get(position));
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        int layoutId = muLayoutId(viewType);
        return ViewHolder.get(mContext,parent,layoutId);
    }

    /**
     * 刷新位置及数据
     * @param position 位置
     * @param t 数据
     * @return
     */
    protected abstract int muItemViewType(int position, T t);

    /**
     * 多布局
     * @param itemType
     * @return
     */
    protected abstract int muLayoutId(int itemType);
}
